/**
 * 注册-创建 i18n 国际化示例
 */
import { I18n, createI18n } from "vue-i18n";
import { useLocaleStore } from "@/store/modules/locale";
import { App } from "vue";

/**
 * 创建 i18n 的配置项
 * @returns 返回 i18n 的配置
 */
async function createI18nOptions() {
	let localeStore = useLocaleStore();
	const locale = localeStore.locale;
	//引入操作-会触发执行对应文件中的代码
	const ZHCNLocal = await import(`./lang/zh-cn.ts`);
	const enLocal = await import(`./lang/en.ts`);
	// const message = defaultLocal.default?.message || {};
	// console.log({ locale, messages: { [locale]: message } }, "I18nOptions");
	return {
		locale,
		messages: {
			"zh-cn": ZHCNLocal.default?.message || {},
			en: enLocal.default?.message || {}
		}
	};
}

export let i18n: I18n<{ [x: number]: any }, {}, {}, any, true>;
export const setupI18n = async (app: App<Element>) => {
	const options = await createI18nOptions();
	console.log(options, "options");
	i18n = createI18n(options);
	app.use(i18n);
};

//增量合并语言包
export const mergeLocaleMessage = () => {};
